/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.daoimpl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.sesame.dao.MessageDAO;
import com.sesame.domain.Message;
import com.sesame.toolkit.Page;

/**
 * @author shubeta
 * 
 */
public class MessageDAOImpl extends SqlMapClientDaoSupport implements
        MessageDAO {

    public void addMessage(Message message) {
        getSqlMapClientTemplate().insert("addMessage", message);
    }

    public void deleteMessageById(Integer id) {
        getSqlMapClientTemplate().delete("deleteMessageById", id);
    }

    public void deleteMessageByState(char state) {
        getSqlMapClientTemplate().delete("deleteMessageByState", state);
    }

    @SuppressWarnings("unchecked")
    public List<Message> getAllMessage() {
        return (List<Message>) getSqlMapClientTemplate().queryForList(
                "getAllMessage");
    }

    public Message getMessageById(Integer id) {
        return (Message) getSqlMapClientTemplate().queryForObject(
                "getMessageById", id);
    }

    public List<Message> getMessageByReceiver(Page page) {
        return (List<Message>) getSqlMapClientTemplate().queryForList(
                "getMessageByReceiver", page);
    }

    public List<Message> getMessageBySender(Page page) {
        return (List<Message>) getSqlMapClientTemplate().queryForList(
                "getMessageBySender", page);
    }

    public void updateMessage(Message message) {
        getSqlMapClientTemplate().update("updateMessage", message);
    }

    public Integer getMessageCount() {
        return (Integer) getSqlMapClientTemplate().queryForObject(
                "getMessageCount");
    }

    public Integer getSendedMessageCount(Integer senderId) {
        return (Integer) getSqlMapClientTemplate().queryForObject(
                "getSendedMessageCount", senderId);
    }

    public Integer getReceivedMessageCount(Integer receiverId) {
        return (Integer) getSqlMapClientTemplate().queryForObject(
                "getReceivedMessageCount", receiverId);
    }

}